class FileListPlugin {
  constructor(options) {
    this.fileName = 'fileList.md'
  }
  apply(compiler) {
    // console.log('file-list-plugin -------')
    compiler.hooks.emit.tap('FileListPlugin', (compilation) => {
      // console.log(compilation.assets)
      const fileCount = Object.keys(compilation.assets).length
      let content = `# 本次打包共生成了 ${fileCount} 个文件\n\n`

      for (const filename in compilation.assets) {
        console.log(filename)
        content += ` - ${filename} \n`
      }

      console.log(content)
      compilation.assets[this.fileName] = {
        source: () => content,
        size: () => content.length,
      }
    })
  }
}

module.exports = FileListPlugin
